# -*- coding: utf-8 -*- 
# 作者:飞虎
# 开发时间:2022/5/4 23:00
# 0. 导入需要的包和模块
from PyQt5.Qt import *
import sys

# 1. 创建一个应用程序对象
app = QApplication(sys.argv)
# 2. 控件的操作
# 2.1 创建控件
window = QWidget()
# 2.2 设置控件
window.setWindowTitle('按钮组的使用')
window.resize(500, 500)

rb_male = QRadioButton('男', window)
rb_female = QRadioButton('女', window)
rb_male.move(100, 100)
rb_female.move(100, 150)
rb_male.setChecked(True)

sex_group = QButtonGroup(window)
sex_group.addButton(rb_male, id=1)
sex_group.addButton(rb_female, id=2)

rb_yes = QRadioButton('Yes', window)
rb_no = QRadioButton('No', window)
rb_yes.move(300, 100)
rb_no.move(300, 150)

answer_group = QButtonGroup(window)
answer_group.addButton(rb_yes)
answer_group.addButton(rb_no)

answer_group.setId(rb_yes, 1)
answer_group.setId(rb_no, 2)
print(answer_group.id(rb_yes))
print(answer_group.id(rb_no))
rb_no.setChecked(True)
print(answer_group.checkedId())

# sex_group.removeButton(rb_female)
# sex_group.setExclusive(False)
# print(sex_group.button(1))
# print(sex_group.checkedButton())
def test(val):
	# print(val)
	print(sex_group.id(val))

sex_group.buttonClicked.connect(test)
# sex_group.buttonClicked[int].connect(test)

# 2.3 展示控件
window.show()
# 3. 应用程序的执行,进入到消息循环
sys.exit(app.exec_())
